/**
  ******************************************************************************
  * @file   :   main.c
  * @version:
  * @author :
  * @brief  :
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright(c) . BLUEX Microelectronics.
  * All rights reserved.</center></h2>
  *
  *
  ******************************************************************************
  */

/* includes ------------------------------------------------------------------*/

#include "bx_kernel.h"

#include "user_app.h"
#include "app_adc_utils.h"

#include "bx_service_adc.h"

#include "bx_shell.h"


/* private define ------------------------------------------------------------*/


/* private typedef -----------------------------------------------------------*/


/* private variables ---------------------------------------------------------*/

/* exported variables --------------------------------------------------------*/
u32 temp;
u32 volt_mv;
u32 bat_value;
u32 channel = 0;
uint32_t Vbat;

/*============================= private function =============================*/

/*========================= end of private function ==========================*/


/*============================= exported function ============================*/
/** ---------------------------------------------------------------------------
 * @brief   :
 * @note    :
 * @param   :
 * @retval  :
-----------------------------------------------------------------------------*/
void user_init( void )
{

    bxs_adc_register();

}

/** ---------------------------------------------------------------------------
 * @brief   :
 * @note    :
 * @param   :
 * @retval  :
-----------------------------------------------------------------------------*/
void user_app( void )
{

    s32 id = bxs_adc_id();

    bx_call( id, BXM_OPEN, 0, 0 );


    bx_repeat( id, BXM_ADC_VOLT, channel, ( u32 )&volt_mv, 500 );
		bx_repeat(id,BXM_ADC_BATTERY , (u32)&bat_value , 0, 500);
		bx_repeat(id,BXM_ADC_TEMPERATURE , (u32)&temp , 0, 500);
    bx_subscibe( id, BXM_ADV_VOLT_DATA_UPDATE, 0, 0 );

    bx_subscibe(id, BXM_ADV_TEMP_DATA_UPDATE, 0 , 0);
		

    bx_subscibe(id, BXM_ADV_BAT_DATA_UPDATE, 0 , 0);
	
		
}




/** ---------------------------------------------------------------------------
 * @brief   :
 * @note    :
 * @param   :
 * @retval  :
-----------------------------------------------------------------------------*/
bx_err_t app_msg_handle( u32 msg, u32 param0, u32 param1 )
{
    return BX_OK;
}

/** ---------------------------------------------------------------------------
 * @brief   :
 * @note    :
 * @param   :
 * @retval  :
-----------------------------------------------------------------------------*/
bx_err_t user_msg_handle_func( s32 id, u32 msg, u32 param0, u32 param1 )
{
	if(bx_msg_source() != bxs_adc_id())
   	{
			bxsh_logln( "msg err");
		return 0;
   }
	
    switch( msg ) {
        case BXM_ADV_VOLT_DATA_UPDATE:
            bxsh_logln( "channel = %d\tvolt_mv = %d\tvolt_mv = %d", param0, param1, volt_mv );
            break;
				
				case BXM_ADV_BAT_DATA_UPDATE:
							bxsh_logln(" bat_value= %d\tparam1 = %d\t",param0,param1);
							break;

				case BXM_ADV_TEMP_DATA_UPDATE:
							bxsh_logln(" temp = %d\tparam1 = %d\t",param0,param1);
							break;
				
        default:
            break;
    }
    return BX_OK;
}
/*========================= end of exported function =========================*/


/*============================= import function ==============================*/

/*=========================== end of import function =========================*/


/*============================ interrupt function ============================*/

/*========================= end of interrupt function ========================*/


/******************** (C) COPYRIGHT BLUEX **********************END OF FILE****/



